
#include <QtGui>
#include <QSpinBox>
//#include <QCheckBox>
#include "QtStra2_InstTableDelegate.h"


//! [0]
QtStra2InstTableDelegate::QtStra2InstTableDelegate(QObject *parent)
    : QItemDelegate(parent)
{
}
//! [0]

//! [1]
QWidget *QtStra2InstTableDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem & option ,
    const QModelIndex & index ) const
{
	if (index.column() != 0)
	{
		QSpinBox *editor = new QSpinBox(parent);
		editor->setMinimum(0);
		editor->setMaximum(100);

		return editor;
	}
	else {
		//return QItemDelegate::createEditor(parent, option, index);
		return NULL;
	}
}
//! [1]

//! [2]
void QtStra2InstTableDelegate::setEditorData(QWidget *editor,
                                    const QModelIndex &index) const
{
	if (index.column() != 0)
	{
		int value = index.model()->data(index, Qt::EditRole).toInt();

		QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
		spinBox->setValue(value);
	}
	//else {
	//	QItemDelegate::setEditorData(editor, index);
	//	//return NULL;
	//}
}
//! [2]

//! [3]
void QtStra2InstTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex &index) const
{
	if (index.column() != 0)
	{
		QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
		spinBox->interpretText();
		int value = spinBox->value();

		model->setData(index, value, Qt::EditRole);
	}


}
//! [3]


